<?php
/**
 * Miffos framework
 * ----------------------------------------------
 *
 * Copyright (c) 2008, 2009 Martin Sadový (http://sodae.cz)
 *
 * This source file is subject to the "Miffos license" that is bundled
 * with this package in the file license.txt.
 *
 * @copyright  Copyright (c) 2008, 2009 Martin Sadový
 * @license    license.txt
 * @link       http://miffos.sodae.cz
 * @package    miffos
 * @version    $Id$
 */

class NamespaceSessionHandler implements IteratorAggregate, ArrayAccess{

    /**
    * Data Session
    * @var $data
    */
    private $data;

    /**
    * Expire Time
    * @var int
    */
    private $expireTime = 0;

    public function __construct(&$namespace)
    {
        $this->data = &$namespace;
    }

    public function __get($name)
    {
        return $this->data->$name;
    }

    public function __set($name,$value)
    {
        $this->data->$name = $value;
    }

    public function __unset($name)
    {
        unset($this->data->$name);
    }

    public function __isset($name)
    {
        return isset($this->data->$name);
    }

    /* interface ArrayAccess */

	public function offsetSet($name, $value)
	{
		$this->__set($name, $value);
	}

	public function offsetGet($name)
	{
		return $this->__get($name);
	}

	public function offsetExists($name)
	{
		return $this->__isset($name);
	}

	public function offsetUnset($name)
	{
		$this->__unset($name);
	}

    public function getIterator()
    {
        if(isset($this->data)){
            return new ArrayIterator($this->data);
        }else{
            return new ArrayIterator;
        }
    }
      /**
       * Set Time Expire
       * @param int $timestamp
       * @return int
       */
      public function setExpiration($timestamp = NULL)
      {
          if($timestamp !== NULL){
              $this->expireTime = $timestamp+time();
          }
          
          return $this->expireTime;
      }
}


?>